package example.collections;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by lenovo on 2016/11/7 0007.
 * Collection 类的 iterator() 方法来遍历集合
 */
public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<String, String> hMap =
                new HashMap<String, String>();
        hMap.put("1", "1st");
        hMap.put("2", "2nd");
        hMap.put("3", "3rd");
        Collection cl = hMap.values();
        Iterator itr = cl.iterator();
        while (itr.hasNext()) {
            System.out.println(itr.next());
        }
        //此处可以用foreach
//        for (Object aCl : cl) {
//            System.out.println(aCl);
//        }
    }
}
